package cn.bouncyslime.algorithms.math.greatestCommonDivisor;

import java.util.Arrays;

public class Test2 {
    public static void main(String[] args){
        int num1=12, num2=30, num3=50;
        int[] numArray = new int[3];
        numArray[0] = num2;
        numArray[1] = num1;
        numArray[2] = num3;
        Arrays.sort(numArray);

        Test2 t = new Test2();
        System.out.println("这几个数的最大公约数为："+t.process(numArray));
    }

    public int process(int[] numArray){
        for(int i=0; i<numArray.length-1; i++){
            int m1 = numArray[i];
            int m2 = numArray[i+1];
            while(m2%m1 != 0){
                int temp = m1;
                m1 = m2%m1;
                m2 = temp;
            }
            numArray[i+1] = m1;
        }
        return numArray[numArray.length-1];
    }
}
